package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.PointConfig;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.setPointConfigBean;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.setPointConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.point_change_config;
import com.ymttest.database.model.godmch.point_change_configExample;
import com.ymttest.database.sqlwapper.godmch.point_change_configWapper;
/**
*积分配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setPointConfig{
	private static setPointConfigBean bean;
	private static setPointConfigCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("积分配置");
	}

	@Before
	public void caseUp() {
		bean=new setPointConfigBean();
		call=new setPointConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setPointConfig_001() {
		Logger.start(true,"积分配置-pointType=100");
		try {
			//pointType = godmchdb.point_change_type_dic.change_type_level = 0 的类型
			//积分值 >= 0
			//请求参数 pointConfigList.size 必须等于 godmchdb.point_change_type_dic.change_type_level = 0 的记录数
		    createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();
			
            List<PointConfig> list=new ArrayList<>();
            PointConfig config=new PointConfig();
            config.setPointType(100);
            config.setPoint(20);
            list.add(config);
            bean.setMchId(mchId);
            bean.setEnabled(true);
            bean.setPointConfigList(list);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证statusCode");
			point_change_configWapper configWapper=new point_change_configWapper();
			point_change_configExample example=new point_change_configExample();
			example.createCriteria().andMch_idEqualTo(bean.getMchId());
			List<point_change_config> DB_configs=configWapper.selectByExample(example);
			for(int i=0;i<DB_configs.size();i++)
			{
				Logger.verifyEquals(list.size(), DB_configs.size(), "验证传入数据与数据库数量一致");
				Logger.verifyEquals(list.get(i).getPointType(), DB_configs.get(i).getChange_type_id(), "验证传入PointType与数据库一致");
				Logger.verifyEquals(list.get(i).getPoint(), DB_configs.get(i).getPoint_value(), "验证传入Point与数据库一致");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setPointConfig_002() {
		Logger.start(true,"积分配置-pointType=101-point_change_type_dic表不存在的配置");
		try {
			//pointType = godmchdb.point_change_type_dic.change_type_level = 0 的类型
			//积分值 >= 0
			//请求参数 pointConfigList.size 必须等于 godmchdb.point_change_type_dic.change_type_level = 0 的记录数
		    createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();
			
            List<PointConfig> list=new ArrayList<>();
            PointConfig config=new PointConfig();
            config.setPointType(101);
            config.setPoint(30);
            list.add(config);
            bean.setMchId(mchId);
            bean.setEnabled(true);
            bean.setPointConfigList(list);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("500", call.getStatusCode1(), "验证statusCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}